package com.heima.controller;

import com.heima.pojo.dto.SkuClassDto;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.SkuClassVo;
import com.heima.service.SkuClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/vm-service/skuClass")
public class SkuClassController {
    @Autowired
    private SkuClassService skuClassService;

    @PostMapping
    public Boolean addCategory(@RequestBody SkuClassDto skuClassDto) {
        skuClassService.add(skuClassDto);
        return true;
    }

    @GetMapping("/search")
    public PageResponse search(@RequestParam(value = "pageIndex", required = false, defaultValue = "1") Integer pageIndex,
                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                               @RequestParam(value = "className", required = false) String className) {
        PageResponse pageResponse = skuClassService.search(pageIndex, pageSize, className);
        return pageResponse;
    }

    @GetMapping("/{classId}")
    public SkuClassVo searchById(@PathVariable("classId") String classId) {
        SkuClassVo vo = skuClassService.searchById(classId);
        return vo;
    }

    @PutMapping("/{classId}")
    public Boolean updateByClassId(@PathVariable("classId") String classId,@RequestBody SkuClassDto skuClassDto){
        skuClassService.updateByClassId(classId, skuClassDto);
        return true;
    }

    @DeleteMapping("/{classId}")
    public void deleteByClassId(@PathVariable("classId") String classId){
        skuClassService.deleteByClassId(classId);
    }
}
